package shopping.stateless;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import shopping.model.Account;
import shopping.remote.IAccountRemote;

@Stateless(name = "AccountStateless", mappedName = "ejb/AccountStateless")
public class AccountStateless implements IAccountRemote {
	@PersistenceContext(unitName = "sem")
	EntityManager em;

	public AccountStateless() {
	}

	@Override
	public Account getAccount(String accountName) {
		Account account = em.find(Account.class, accountName);
		return account;
	}

	@Override
	public Account getAccount(String accountName, String password) {
		Account account = em.find(Account.class, accountName);
		if(account == null){
			return null;
		}
		if(password.equals(account.getPassword())){
			return account;
		}
		return null;
	}
}
